﻿@model InspectionModel
@using Nop.Web.Framework.Localization
@using Nop.Core.Domain.XJ

@Html.ValidationSummary(true)
@Html.HiddenFor(model => model.Id)

<script>
    $(document).ready(function () {
        bindBootstrapTabSelectEvent('category-edit');
    });
</script>

<style type="text/css">
    .pic {
        width: 200px;
        height: 200px;
        object-fit: cover;
    }
</style>

<div class="content">
    <div class="form-horizontal">
        <div class="row">
            <div class="col-md-12 clearfix">
                <div class="pull-left">
                    @Html.Action("Mode", "Setting", new { modeName = "category-advanced-mode" })
                </div>
            </div>
        </div>
        <div id="category-edit" class="nav-tabs-custom">
            <ul class="nav nav-tabs">
                @Html.RenderBootstrapTabHeader("tab-info", new LocalizedString("基本信息"), true)
            </ul>
            <div class="tab-content">
                @Html.RenderBootstrapTabContent("tab-info", @TabInfo(), true)
            </div>
        </div>
    </div>
</div>

@{
    //custom tabs
    var eventMessage = new AdminTabStripCreated(this.Html, "category-edit");
    EngineContext.Current.Resolve<IEventPublisher>().Publish(eventMessage);
    foreach (var eventBlock in eventMessage.BlocksToRender)
    {
        @eventBlock
    }
}

@*save selected tab name*@
<input type="hidden" id="selected-tab-name" name="selected-tab-name" value="@(Html.GetSelectedTabName())">

@helper TabInfo()
{
    <div class="content">
        <div class="form-horizontal">
            <div class="panel-group">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="form-group">
                            <div class="col-md-3">
                                @Html.NopLabelFor(model => model.PNo)
                            </div>
                            <div class="col-md-9">
                                @Html.NopDisplayFor(model => model.PNo)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                巡检类型
                            </div>
                            <div class="col-md-9">
                                @Html.NopDisplayFor(model => model.TypeName)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                设备分类
                            </div>
                            <div class="col-md-9">
                                @Html.NopDisplayFor(model => model.CategoryNames)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                设施设备
                            </div>
                            <div class="col-md-9">
                                @Html.NopDisplayFor(model => model.EquipmentName)
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="col-md-3">
                                巡检班组
                            </div>
                            <div class="col-md-9">
                                @Html.NopDisplayFor(model => model.TeamName)
                            </div>
                        </div>
                        @if (Model.State == (int)InspectionStateEnum.待巡检)
                        {
                            <div class="form-group">
                                <div class="col-md-3">
                                    计划巡检人员
                                </div>
                                <div class="col-md-9">
                                    @Html.NopDisplayFor(model => model.PersonName)
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-3">
                                    计划巡检时间
                                </div>
                                <div class="col-md-9">
                                    @Html.NopDisplayFor(model => model.StartOn) -
                                    @Html.NopDisplayFor(model => model.EndOn)
                                </div>
                            </div>
                        }
                        else
                        {
                            <div class="form-group">
                                <div class="col-md-3">
                                    巡检人
                                </div>
                                <div class="col-md-9">
                                    @Html.NopDisplayFor(model => model.InspectionPersonName)
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-3">
                                    巡检时间
                                </div>
                                <div class="col-md-9">
                                    @Html.NopDisplayFor(model => model.InspectionOn)
                                </div>
                            </div>
                            <div class="form-group">
                                <div class="col-md-3">
                                    巡检图片
                                </div>
                                <div class="col-md-9">
                                    @foreach (var item in Model.Pictures)
                                    {
                                        <img src="@item" class="pic" />
                                    }
                                </div>
                            </div>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="content" style="padding-top:0;">
        <div class="form-horizontal">
            <div class="panel-group">
                @if (Model.Id > 0)
                {
                    <div class="content-header clearfix" style="padding-top:0;">
                        <h1 class="pull-left">
                            维修申请
                        </h1>
                        <div class="pull-right">
                            @*@if (Model.State == (int)InspectionStateEnum.待巡检)
                            {
                                <button type="submit" id="btnAddNewEquipment"
                                        onclick="javascript:OpenWindow('@(Url.Action("AddPopup", "Maintenance", new {inspectionId = Model.Id, btnId = "btnRefreshMaintenances", formId = "inspection-form"}))', 1000, 800, true); return false;"
                                        class="btn btn-primary">
                                    <i class="fa fa-plus"></i>
                                    添加
                                </button>
                            }*@
                            <input type="submit" id="btnRefreshMaintenances" style="display: none" />
                        </div>
                    </div>
                    <div class="panel panel-default">
                        <div class="panel-body">
                            @{
                                var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
                                var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;
                            }


                            <div id="products-grid"></div>

                            <script>
                    $(document).ready(function() {
                        $("#products-grid").kendoGrid({
                            dataSource: {
                                type: "json",
                                transport: {
                                    read: {
                                        url: "@Html.Raw(Url.Action("Maintenances", "Inspection", new { inspectionId = Model.Id}))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    },
                                    destroy: {
                                        url: "@Html.Raw(Url.Action("MaintenanceDelete", "Inspection"))",
                                        type: "POST",
                                        dataType: "json",
                                        data: addAntiForgeryToken
                                    }
                                },
                                schema: {
                                    data: "Data",
                                    total: "Total",
                                    errors: "Errors",
                                    model: {
                                        id: "Id",
                                        fields: {
                                            Name: { editable: false, type: "string" },
                                            ProductionDate: { editable: false, type: "date" },
                                            Published: { editable: true, type: "boolean" },
                                            DisplayOrder: { editable: true, type: "number" },
                                            Id: { editable: false, type: "number" }
                                        }
                                    }
                                },
                                requestEnd: function(e) {
                                    if (e.type == "update") {
                                        this.read();
                                    }
                                },
                                error: function(e) {
                                    display_kendoui_grid_error(e);
                                    // Cancel the changes
                                    this.cancelChanges();
                                },
                                pageSize: @(defaultGridPageSize),
                                serverPaging: true,
                                serverFiltering: true,
                                serverSorting: true
                            },
                            pageable: {
                                refresh: true,
                                pageSizes: [@(gridPageSizes)],
                                @Html.Partial("_GridPagerMessages")
                            },
                            editable: {
                                confirmation: "@T("Admin.Common.DeleteConfirmation")",
                                mode: "inline"
                            },
                            scrollable: false,
                            columns: [{
                                field: "EquipmentName",
                                title: "设施设备",
                                width: 80,
                                headerAttributes: { style: "text-align:center" },
                                attributes: { style: "text-align:center" },
                            }, {
                                    field: "TeamName",
                                    title: "计划巡检班组",
                                    width: 80,
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                }, {
                                    field: "PersonName",
                                    title: "计划巡检人员",
                                    width: 80,
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                }, {
                                    field: "MaintenancePersonName",
                                    title: "维修人",
                                    width: 80,
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                }, {
                                    field: "MaintenanceOn",
                                    title: "维修时间",
                                    width: 100,
                                    type: "date",
                                    format: "{0:yyyy/MM/dd}",
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                }, {
                                    field: "StateName",
                                    title: "状态",
                                    width: 80,
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                } ,  {
                                    field: "Id",
                                    title: "@T("Admin.Common.Edit")",
                                    width: 100,
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                    template: '# if(State!=@((int)MaintenanceStateEnum.已完工)){# <a class="btn btn-default" href="javascript: OpenWindow(\'@(Url.Action("EditPopup", "Maintenance"))/#=Id#?btnId=btnRefreshMaintenances&formId=inspection-form\', 1000, 800, true);"><i class="fa fa-pencil"></i>@T("Admin.Common.Edit")</a> #} #'
                                }
                                @*, {
                                    title: "操作",
                                    headerAttributes: { style: "text-align:center" },
                                    attributes: { style: "text-align:center" },
                                    command: [{
                                            name: "destroy",
                                            text: "@T("Admin.Common.Delete")"
                                        }
                                    ],
                                    width: 100
                                }*@
                            ]
                        });
                        $('#btnRefreshMaintenances').click(function () {
                            //refresh grid
                            var grid = $("#products-grid").data('kendoGrid');
                            grid.dataSource.read();

                            //return false to don't reload a page
                            return false;
                        });
                    });
                            </script>
                        </div>
                    </div>
                }
                else
                {
                    <div class="panel panel-default">
                        <div class="panel-body">
                            @T("Admin.Catalog.Categories.Products.SaveBeforeEdit")
                        </div>
                    </div>
                }
            </div>
        </div>
    </div>
}
